//
//  ImportantAreaManipulatorViewController.m
//  Utils
//
//  Created by enghou on 2018/6/7.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "ImportantAreaManipulatorViewController.h"
#import "AddImportantViewController.h"
#import "ImportAreaItemModel.h"
#import "QuestionSearchViewController.h"
@interface ImportantAreaManipulatorViewController ()

@end

@implementation ImportantAreaManipulatorViewController

-(instancetype)init{
    self = [super init];
    if (self) {
//        /mobile/comprehensiveGovernance/socialSecurity/searchSocialSecurity.action
        self.path = @"/mobile/comprehensiveGovernance/socialSecurity/getSocialSecurityList.action";
        self.modelClsName = @"ImportAreaItemModel";
        self.cellClass = @"ImportAreaCell";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(beginRefresh) name:@"RefreshImportantList" object:nil];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

-(NSDictionary *)param{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    NSString *orgid = [self orgId];
//    self.orgId
    if (orgid) {
        [param setObject:orgid forKey:@"orgId"];
    }
    if ([self.choosenParam isKindOfClass:[NSDictionary class]]) {
        [param addEntriesFromDictionary:self.choosenParam];
    }else if ([self.choosenParam isKindOfClass:[NSString class]]){
        [param setObject:self.choosenParam forKey:@"orgId"];
    }
    
    return param;
}

-(void)fetchModel:(id)model{
    if ([model isKindOfClass:[NSString class]]) {
        self.orgId = model;
        [self beginRefresh];
        return;
    }else if ([model isKindOfClass:[NSDictionary class]]){
        self.choosenParam = model;
    }
    [self beginLoading];
    [[NetWorkerManager sharedInstance]postWithPath:@"/mobile/comprehensiveGovernance/socialSecurity/searchSocialSecurity.action" parameter:[self param] completeBlock:^(NSDictionary *source) {
        [self endLoading];
        BaseModel *model = [[BaseModel alloc]initWithSourceDict:source listItemClass:NSClassFromString(self.modelClsName)];
        if (model.success) {
            [self refreshSuccessWithModel:model];
        }else{
            [self commonFailBlockWithModel:model];
        }
    } failBlock:^(NSInteger code) {
        [self endLoading];
        [self alertSome:kNetWorkFail];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)searchAction{
    QuestionSearchViewController *search = [[QuestionSearchViewController alloc]init];
    search.theDelegate = self;
    search.needParameter = YES;
    [self push:search];
}

-(void)addAction{
    AddImportantViewController *add = [[AddImportantViewController alloc]init];
    [self push:add];
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ImportAreaItemModel *model = [self.source objectAtIndex:indexPath.row];
    AddImportantViewController *add = [[AddImportantViewController alloc]init];
    add.ids = model.ids;
    add.title = @"排查整治详情";
    [self push:add];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    BaseItemModel *model = [self.source objectAtIndex:indexPath.section];
    return model.height;
}

@end
